# ------------------------------------------
# 准备工作
# ------------------------------------------

setwd("/Users/eimei/Documents/Rdata/")  # 设定工作空间
data <- read.csv("HRdata.csv")  # 读取数据

newdata <- data[c("EmployeeNumber", "Age", "Department",
                  "EnvironmentSatisfaction", "JobSatisfaction",
                  "MonthlyIncome", "RelationshipSatisfaction")]

head(newdata)

# ------------------------------------------
# 任务一
# ------------------------------------------
newdata$EnvironmentSatisfaction[newdata$EnvironmentSatisfaction == 1] <- "非常不满意"
newdata$EnvironmentSatisfaction[newdata$EnvironmentSatisfaction == 2] <- "比较不满意"
newdata$EnvironmentSatisfaction[newdata$EnvironmentSatisfaction == 3] <- "一般不满意"
newdata$EnvironmentSatisfaction[newdata$EnvironmentSatisfaction == 4] <- "比较满意"
newdata$EnvironmentSatisfaction[newdata$EnvironmentSatisfaction == 5] <- "非常满意"
head(newdata)

# ------------------------------------------
# 任务二
# ------------------------------------------
newdata$AgeGroup <- NA
newdata$AgeGroup[newdata$Age <= 20] <- "10+"
newdata$AgeGroup[newdata$Age > 20 & newdata$Age <= 30] <- "20+"
newdata$AgeGroup[newdata$Age > 30 & newdata$Age <= 40] <- "30+"
newdata$AgeGroup[newdata$Age > 40 & newdata$Age <= 50] <- "40+"
newdata$AgeGroup[newdata$Age > 50 & newdata$Age <= 60] <- "50+"
head(newdata)


# ------------------------------------------
# 任务三
# ------------------------------------------
newdata <- within(newdata, {
                 MonthlyIncomeGroup <- NA
                 MonthlyIncomeGroup[MonthlyIncome <= 6503] <- "低收入"
                 MonthlyIncomeGroup[MonthlyIncome > 6503] <- "高收入"})
head(newdata)